<template>
  <div class="perset">
    <van-nav-bar
      title="设置"
      left-arrow
      @click-left="onClickLeft"
      :fixed="true"
      :placeholder="true"
    />
    <van-uploader :max-count="1" :after-read="afterRead" />
    <van-field :center="true" label="用户名" readonly value="anrun7" />
    <van-field :center="true" label="昵  称" v-model="nickname" value="" />
    <van-field :center="true" label="个性签名" v-model="sign"  />
    <van-cell :center="true" title="更改密码" to="/updatepwd" is-link />
    <!-- <van-field :center="true" type="password" v-model="oldpwd" label="旧密码" value=""   />
    <van-field :center="true" type="password" v-model="newpwd" label="新密码" value="" /> -->
    <van-button type="primary" @click="update" size="large">保存</van-button>
    <van-button class="tuichu" @click="quit" size="large" color="red" plain type="primary"
      >退出当前账号</van-button >
  </div>
</template>
<script>
export default {
  data() {
    return {
      toux: "",
      nickname: "",
      oldpwd:"",
      newpwd:"",
      sign:""
    };
  },
  methods: {
    // 修改用户信息
    update(){
      if(this.$store.state.islogin==0){
        this.$toast.fail("请先登入！");
        return;
      }      
      // 修改用户昵称
      if(this.nickname!=""){
        console.log(this.nickname)
        this.axios.post('/users/upnickname',`nickname=${this.nickname}&uid=${this.$store.state.userid}`).then(result=>{
          
          console.log(result)
        })
      }
      // 修改用户签名
      if(this.sign!=""){
        this.axios.post('/users/upsign',`sign=${this.sign}&uid=${this.$store.state.userid}`).then(result=>{
          console.log(result)
        })
      }
      this.$router.push(`/personal`)
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      console.log(file);
    },
    quit(){
      // this.$$store.state
      sessionStorage.clear()
      this.$router.push('/')
      sessionStorage.setItem("islogin",0);
      this.$store.commit("setIslogin",0);
    }
  },
};
</script>
<style lang="scss">
.perset {
  .van-icon-arrow-left::before {
    color: black;
  }
  .van-cell {
    height: 55px;
    color: #646566;
  }
  .van-uploader__wrapper{
    margin: 20px 0 0 152px;
  }
  .tuichu{
    margin-top:150px ;
    // position: absolute;
    // top: 10px;
    // bottom: 10px;
  }
}
</style>